package cn.wolfcode.luowowo.acticle.service.impl;


import cn.wolfcode.luowowo.acticle.domain.StrategyTheme;
import cn.wolfcode.luowowo.acticle.mapper.StrategyThemeMapper;
import cn.wolfcode.luowowo.acticle.service.IStrategyThemeService;
import cn.wolfcode.luowowo.common.exception.DisplayableException;
import cn.wolfcode.luowowo.common.query.QueryObject;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Component
@Transactional
@Service
public class StrategyThemeServiceImpl implements IStrategyThemeService {
    @Autowired
    private StrategyThemeMapper strategyThemeMapper;

    @Override
    public PageInfo query(QueryObject qo) {

        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());

        return new PageInfo(strategyThemeMapper.selectForList(qo));
    }

    @Override
    public void saveOrUpdate(StrategyTheme strategyTheme) throws DisplayableException {
        if(strategyTheme.getId() == null){
            strategyThemeMapper.insert(strategyTheme);
        }else{
            strategyThemeMapper.updateByPrimaryKey(strategyTheme);
        }
    }

    @Override
    public void delete(Long id) throws DisplayableException {
        strategyThemeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<StrategyTheme> list() {
        return strategyThemeMapper.selectAll();
    }
}
